package com.point.business.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.point.business.database.managers.InformationManager;
import com.point.business.util.UTFUtil;

/**
 * Servlet implementation class LoginServlet
 */
public class AllProcedureTypesSLServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public AllProcedureTypesSLServlet() {
		super();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json");
		UTFUtil.utf8(request, response);
		PrintWriter out = response.getWriter();
		List<String> procedureTypes = InformationManager.getInstance()
				.getSLTypes();
		JsonArray result = new JsonArray();
		JsonObject object = new JsonObject();
		object.addProperty("value", "Сите");
		result.add(object);
		for (int i = 0; i < procedureTypes.size(); i++) {
			object = new JsonObject();
			object.addProperty("value", procedureTypes.get(i));
			result.add(object);

		}

		out.print(result);
	}
}
